package com.lianniu.web.product.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.lianniu.web.base.BaseResult;
import com.lianniu.web.constants.ErrorCode;
import com.lianniu.web.pagination.PaginationInfo;
import com.lianniu.web.product.dao.ISupplyareaDao;
import com.lianniu.web.product.model.SupplyareaVo;
import com.lianniu.web.product.service.ISupplyareaService;
import com.lianniu.web.util.StringUtil;
@Service
public class SupplyAreaServiceImpl implements ISupplyareaService {
    
  private final static Logger logger = Logger.getLogger(SupplyAreaServiceImpl.class);
  @Autowired
  ISupplyareaDao SupplyareaDao;
  
@Override
public BaseResult selectById (SupplyareaVo record ){
logger.info("selectById begin.");
logger.info("selectById Id:" +record.getSupplyID());
    if(record.getID()==null){
        return BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
    }
    return BaseResult.success(SupplyareaDao.selectById(record.getID()));   
} 


@Override
public BaseResult deleteSupplyareaBatch (String... id ){
    logger.info("deleteSupplyareaBatch begin");
    logger.info("deleteSupplyareaBatch Ids:"+id.toString());
    logger.info("deleteSupplyareaBatch: input data check begin");
     BaseResult baseResult;
     if (StringUtil.isEmpty(id.toString())) {
      baseResult =  BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
      return baseResult;
    }
    logger.info("deleteSupplyareaBatch: input data check end");
    return BaseResult.success(SupplyareaDao. deleteSupplyareaBatch (id));   
} 

@Override
public BaseResult insertSupplyarea( SupplyareaVo record ){
        logger.info("insertSupplyarea begin");
         logger.info("insertSupplyarea: input data check begin");
        logger.info("insertSupplyarea record:" +JSON.toJSONString(record));
        logger.info("insertSupplyarea end");
        return BaseResult.success(SupplyareaDao.insertSupplyarea(record));

} 
@Override
public BaseResult UpdateById( SupplyareaVo record ){
        logger.info("updateById begin");
        logger.info("updateById: update data check begin");
        logger.info("updateById record:" +JSON.toJSONString(record));
    if(record.getID()!=null){
        return BaseResult.success(SupplyareaDao.updateById(record));

} 
        return BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
} 
@Override
public  BaseResult selectBySupplyareaForPage( SupplyareaVo record,PaginationInfo paginationInfo ){
        logger.info("selectBySupplyareaForPage begin.");
        record.setPaginationInfo(paginationInfo);
     List<SupplyareaVo> list=SupplyareaDao.selectBySupplyareaForPage(record); 
     Map<String,Object> retmap=new HashMap<String,Object>(); 
     retmap.put("total", paginationInfo.getTotalRecord()); 
     retmap.put("curPage", paginationInfo.getCurPage()); 
     retmap.put("rows", list);
     logger.info("selectBySupplyareaForPage:  end");
     return BaseResult.success(retmap); 
}
    @Override
    public BaseResult selectSupplyArea(String supplyId) {
       logger.info("selectSupplyArea begin");
        return BaseResult.success(SupplyareaDao.selectSupplyArea(supplyId));
    }

}
